import time

from selenium.webdriver.common.by import By

from pages.base_page import BasePage
from pages.elements import Elements
from pages.login_sucess_page import LoginSuccessPage
from pages.reg_page import RegPage
from utils.log_manager import my_logger

class LoginPage(BasePage):

    url = 'http://192.168.1.4:9000/#/login'

    def login_by_phone(self,phone,passwd):
        self.input_data(Elements.USER_NAME_ELE,phone)
        self.input_data(Elements.PASSWORD_ELE, passwd)
        self.click_element(Elements.LOGIN_BTN_ELE)
        return LoginSuccessPage()


    def go_to_reg(self):
        time.sleep(1)
        self.click_element(Elements.TO_REG_BTN)
        return RegPage()

    def is_login_success(self):
        time.sleep(1)
        try:
            current_url = self.driver.current_url
            my_logger.logger.info("登录后跳转的地址:{}",current_url)
            if 'index' in current_url:
                return True
        except:
            return False
        return False





